package text.java;

import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pojo.SysUser;
import service.SysUserService;

import java.sql.Date;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

public class SysUserTest {
    private Logger logger = Logger.getLogger(SysUserTest.class);
    @Before
    public void setUp() throws Exception{}
    @Test
    public void testGetUserList(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext-Dao.xml","applicationContext-service.xml");
        SysUserService userService =  context.getBean(SysUserService.class);
        List<SysUser> userList = new ArrayList<SysUser>();
        SysUser userCondition = new SysUser();
        userCondition.setRealName("赵");
        userCondition.setRoleId(2);
        userList = userService.getList(userCondition);
        for (SysUser userResult:userList){
            logger.debug("testGetUserList account:"
                    + userResult.getAccount()+ "and realName:"
                    + userResult.getRealName() + "and roleId:"
                    + userResult.getRoleId() + "and roleName:"
                    + userResult.getRoleIdName() + "and address:"
                    + userResult.getAddress()
            );
        }
    }

    @Test
    public void testAddUser()throws ParseException{
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService =  context.getBean(SysUserService.class);
        SysUser sysUser = new SysUser();
        sysUser.setAccount("400881");
        sysUser.setRealName("李四");
        sysUser.setPassword("123456");
        sysUser.setSex(1);
        sysUser.setBirthday(new Date(System.currentTimeMillis()));
        sysUser.setPhone("13203394521");
        sysUser.setRoleId(1);
        sysUser.setAddress("郴州");
        sysUser.setCreatedTime(new Date(System.currentTimeMillis()));
        sysUser.setCreatedUserId(1);
        boolean result = userService.add(sysUser);
        logger.debug("testAdd result：" + result);
    }

}
